<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // function Dog(name){
        //     this.name = name;
        //     this.eat = function(){
        //         console.log('eat');
        //     }
        //     this.lookDoor = function(){
        //         console.log('看门')
        //     }
        // }
        // let d = new Dog('小明');

        // let d2 = new Dog('旺财');

        // d.eat();
        // d2.lookDoor();
        // console.log(d.eat == d2.eat);//false

        // 使用全局变量保存公共函数
        function eat(){
            console.log(this.name +' 正在吃食物');
        }
        function Dog(name){
            this.name = name;
            // 将当前对象下的eat属性值设置为eat函数对应的地址
            this.eat = eat;
        }
        let d = new Dog('小明');

        let d2 = new Dog('旺财');

        // 如果有人修改了eat  将eat变量栈区的值赋值为一个新的地址。没有讲以前eat在堆区对应的数据销毁(被d与d2占用)
        eat = [];

        d.eat()

        let d3 = new Dog('来福')
        d3.eat();//无法调用


    </script>
</body>
</html>